package com.fansl.allround.study.spring.singlebean;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @author fansl
 * @Description: 如何在单例Bean中注入原型Bean
 * https://mp.weixin.qq.com/s/OTRiKwE7Mk1PaX3q0WAPqQ
 * @date 2019/10/11 9:58
 */
@Configuration
@ComponentScan
public class InjectedSpringBean {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext context =
                new AnnotationConfigApplicationContext(InjectedSpringBean.class);
        UserService userService = context.getBean(UserService.class);
        OrderService orderService = userService.getOrderService();
        OrderService orderService1 = userService.getOrderService();
        //ture
        System.out.println(orderService == orderService1);

        UserServiceImpl1 userServiceImpl1 = context.getBean(UserServiceImpl1.class);
        System.out.println(userServiceImpl1.getOrderService()==userServiceImpl1.getOrderService());

        UserServiceImpl2 userServiceImpl2 = context.getBean(UserServiceImpl2.class);
        System.out.println(userServiceImpl2.getOrderServiceUsingLookup()==userServiceImpl2.getOrderServiceUsingLookup());
    }
}
